<?php

namespace app\modules\device\models;

use app\common\base\CommonModel;
use yii\helpers\ArrayHelper;

class DeviceData extends CommonModel
{
    public static function tableName()
    {
        return '{{%device_data}}';
    }

    /**
     * rules
     *
     * @return array
     */
    public function rules()
    {
        return [
            ['deviceId', 'required'],
            [['deviceId', 'timestamp'], 'integer'],
            [['ph', 'cod', 'oxygen', 'nh4n', 'phosphorus', 'colorDe', 'turbidity', 'conductivity', 'flow', 'tem'], 'number'],
        ];
    }


    public function behaviors()
    {
        return parent::behaviors();
    }

    public function fields()
    {
        $fields = parent::fields();

        if (isset($fields['create_timestamp'])) {
            $fields['time'] = function ($model) {
                return date("Y-m-d H:i", $model->create_timestamp / 1000);
            };
        }
        return $fields;
    }
}
